<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>VUE学习 - Axios封装解构</title>
</head>

<body>


    <!--载入vue.js-->
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

    <div id="Application">

        您的名字是：{{data.name}} <br />
        您的ID是：{{data.id}}

    </div>
    <script>
        const app = Vue.createApp({
            setup() {
                const data = Vue.ref("");
                const api = {
                    //GET请求
                    async get(url, data) {
                        try {
                            let res = await axios.get(url, { params: data })
                            res = res.data
                            return new Promise((resolve) => {
                                resolve(res)
                            })
                        }
                        catch (err) {
                            alert("服务器错误")
                            console.log(err)
                        }
                    },
                };
                async function getList() {
                    let dataList = await api.post('https://rouse.npc.ink/api/data.php');
                    let { name, id, age } = dataList;
                    console.log(dataList);
                    console.log(name, id, age);
                    data.value = dataList;
                }
                getList();
                return { data };
            },
        })

        app.mount("#Application")
    </script>

</body>

</html>